<?php
session_start();
//include ('transform.php');
include ('../parametros/bd.php');
$conect = new conector_pg();
$conect-> conectar();
$id=$_GET['id'];

if ($id!= null){
$sql='SELECT *
		from authentication		
		where iduser='.$id;
$result = $conect->consultar($sql);
		if (!$result)
		 {
			echo ('Error en la consulta');
			return;
		 }
$valor = pg_fetch_array($result, null, PGSQL_ASSOC);
}


if($_SERVER["REQUEST_METHOD"] == "POST"){
	if (isset($_POST["guardar"])){
		
		$upd="update authentication
				set  username='".$_POST['username']."',
				     direccion='".$_POST['direccion']."',
				     email='".$_POST['email']."',
				     nombre='".$_POST['nombre']."',
				     apellido='".$_POST['apellido']."',
				     admin='".$_POST['admin']."',
				     estado='".$_POST['estado']."'
				where iduser='".$_POST['iduser']."'";
		 
		$result = $conect->consultar($upd);
			if (!$result)
		 	{
				echo 'error en la consulta'	;
				exit;
		 	}else{
		 		header("Location: verusuarios.php");
		 	}		
	}
}

?>
<?php if (isset($_SESSION['logged_in'])) 
	   { 
	   	if ($_SESSION['admin'] == 1)
	   	{ 
?>
<html>
<head>
<link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" />
<link href="../css/imageMenu.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="XoR-main">
			<div class="XoR-sheet">
				<div class="XoR-sheet-tl"></div>
				<div class="XoR-sheet-tr"></div>
				<div class="XoR-sheet-bl"></div>
				<div class="XoR-sheet-br"></div>
				<div class="XoR-sheet-tc"></div>
				<div class="XoR-sheet-bc"></div>
				<div class="XoR-sheet-cl"></div>
				<div class="XoR-sheet-cr"></div>
				<div class="XoR-sheet-cc"></div>
				<div class="XoR-sheet-body">
					<div class="XoR-header">
						<div class="XoR-header-center">
							<div class="XoR-header-png"></div>
							<div class="XoR-header-jpeg"></div>
						</div>
						<div class="XoR-logo">
							<h1 id="name-text" class="XoR-logo-name"><a href="./index.html">Libreria TAI</a></h1>
							<h2 id="slogan-text" class="XoR-logo-text">Primera Libreria Online del Paraguay</h2>
						</div>
					</div>
<h1 id="tituloNaranja2">Edicion de usuarios</h1>
<form action="edicionusuario.php" method="POST">
<table> 
  <tr>
    <th id="labelLogin">Username</th>
    <td><input type="text" name="username" id="searchForm" value="<?echo $valor['username'];?>"> </td>
  </tr>
  <tr>  
    <th id="labelLogin">Nombre</th>
    <td><input type="text" name="nombre" id="searchForm" value="<?echo $valor['nombre'];?>" ></td>
  </tr>
  <tr>  
    <th id="labelLogin">Apellido</th>
    <td><input type="text" name="apellido" id="searchForm" value="<?echo $valor['apellido'];?>"> </td>
  </tr>
  <tr>  
    <th id="labelLogin">Email</th>
    <td><input type="text" name="email" id="searchForm" value="<?echo $valor['email'];?>" ></td>
  </tr>
  <tr>  
    <th id="labelLogin">Direccion</th>
    <td><input type="text" name="direccion" id="searchForm" value="<?echo $valor['direccion'];?>" ></td>
  </tr>
  <tr>  
    <th id="labelLogin">Privilegios</th>
    <td>    <select name="admin" id="searchForm">
    			<?if ($valor['admin']==1){
    				echo '<option value="1">Admin</option>
						  <option value="0">Usuario</option>';	
    			}else{
    				echo '<option value="0">Usuario</option>
    					  <option value="1">Admin</option>';
    			}?>	
				
			</select>
	</td>
  </tr>
  <tr>  
    <th id="labelLogin">Estado</th>
    <td>    <select name="estado" id="searchForm">
    			<?if ($valor['estado']==1){
    				echo '<option value="1">Activo</option>
						  <option value="0">Inactivo</option>';	
    			}else{
    				echo '<option value="0">Inactivo</option>
    					  <option value="1">Activo</option>';
    			}?>	
				
			</select>
	</td>
  </tr>
  <tr>
  <td><input style="visibility:hidden" name="iduser" type="text" value="<?echo ($id);?>"></td>
  </tr>
</table>

<input type="submit" value="Guardar" id="submitLogin" name="guardar">
</form>

<br>
<a id="labelLogin" href="indexadmin.php"> Regresar al listado </a>
	   	<?php 
	   	}
?>
<a href="../login/logout.php?signature=<?php echo $_SESSION['signature']; ?>
">Logout</a><br /><?php } 
?>
<div class="cleared"></div>
					<div class="XoR-footer">
						<div class="XoR-footer-body">
							<div class="XoR-footer-text">
								<p>Copyright 2011, XoR Company. All Rights Reserved.</p>
							</div>
							<div class="cleared"></div>
						</div>
					</div>
					<div class="cleared"></div>
				</div>
			</div>
			<div class="cleared"></div>
			<p class="XoR-page-footer">Powered by <a href="http://xor.net/">XoR.org</a> </p>
		</div>
</body>  